Debugging COM Interop: .NET DLL With VB6 .EXE

Mark Leighton Fisher on 2006-02-10T17:20:19

[Yes, I know it's not Perl – but I write my tools in Perl to help with my VB.NET and VB6 development...]

There are two ways to debug a .NET COM Interop DLL used by a VB6 EXE:

  1. Normally, you can use Project -> Properties -> Debug -> Start Action -> Start external program to start VB6.EXE automatically when you click Start Debugging.
     
  2. In Visual Studio 2005 at least, if you have a test project for your DLL in your solution, AND you test that DLL rather than including the DLL sources in the test project (that is, the only source in the test project is for the test code), you will need to explicitly stop at a breakpoint in the VB6 EXE, then attach to that VB6 process with Visual Studio 2005 Tools -> Attach to process. Once you attach to the VB6 EXE, then debugging between the VB6 code and the .NET code is seamless – transitioning between managed and unmanaged code will automatically switch debuggers for you. Apparently, the presence of a test project that tests your DLL (as opposed to a test project that includes the source files for your DLL) confuses Visual Studio just enough that when you click Start Debugging, Visual Studio automagically starts the test project for you instead of the external command you specified.

An example Solution where you cannot debug using Start external program:

Project: Joe.dll
    xyz.vb
    abcd.vb
Project: TestJoe
    UnitTest.vb
    [reference: Joe.dll]